﻿// Spun AJAX Framework
// Copyright (C) 2008 Blake Hegerle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Formality.FormalSystem.Parser
{
    public interface ISentenceFactory
    {
        Axiom Axiom(IEnumerable<Proposition> Antecedents, Proposition Consequent);
        BindingOperator BindingOperator(string Binder, Variable Variable, params Proposition[] Scopes);
        Definition Definition(Proposition Definiendum, Proposition Definiens);
        PrefixOperator PrefixOperator(string Operator, IEnumerable<Proposition> Operands);
        InfixOperator InfixOperator(string Operator, int Precedence, IEnumerable<Proposition> Operands);
        Function Function(Variable Name, params Variable[] Arguments);
        Variable Variable(string Name);
    }

    public class SentenceFactory : ISentenceFactory
    {
        #region ISemanticsFactory Members

        public Axiom Axiom(IEnumerable<Proposition> Antecedents, Proposition Consequent)
        {
            return new Axiom(Antecedents, Consequent);
        }

        public BindingOperator BindingOperator(string Binder, Variable Variable, params Proposition[] Scopes)
        {
            return new BindingOperator(Binder, Variable, Scopes);
        }

        public Definition Definition(Proposition Definiendum, Proposition Definiens)
        {
            return new Definition(Definiendum, Definiens);
        }

        public PrefixOperator PrefixOperator(string Operator, IEnumerable<Proposition> Operands)
        {
            return new PrefixOperator(Operator, Operands);
        }

        public InfixOperator InfixOperator(string Operator, int Precedence, IEnumerable<Proposition> Operands)
        {
            return new InfixOperator(Operator, Precedence, Operands);
        }

        public Function Function(Variable Name, params Variable[] Arguments)
        {
            return new Function(Name, Arguments);
        }

        public Variable Variable(string Name)
        {
            return new Variable(Name);
        }

        #endregion
    }
}
